//
//  UIBarButtonItem+Custom.m
//  Manager
//
//  Created by scho on 2018/11/16.
//  Copyright © 2018 scho. All rights reserved.
//

#import "UIBarButtonItem+Custom.h"
//#import "SchoBaseNavigationController.h"

@implementation UIBarButtonItem (QISCustom)

// use before Xcode9
+ (void)customBarButtonItemAppearance
{
    // custom back button image, hide back title
    
    // Note that images configured as the back bar button's background do
    // not have the current tintColor applied to them, they are displayed
    // as it.
    // note: image right side remain 2 point space to stretch space.
//    UIImage *backButtonBackgroundImage = [UIImage imageNamed:@"navi_back"];
//    // The background should be pinned to the left and not stretch.
//    UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, backButtonBackgroundImage.size.width - 1, 0, 0);
//    backButtonBackgroundImage = [backButtonBackgroundImage resizableImageWithCapInsets:edgeInsets];
//    
//    id appearance = [UIBarButtonItem appearanceWhenContainedIn:[SchoBaseNavigationController class], nil];
//    [appearance setBackButtonBackgroundImage:backButtonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    //appearanceWhenContainedInInstancesOfClasses
}

// navi back image
+ (nonnull UIBarButtonItem*)customBackButtonForNaviBar
{
    // Provide an empty backBarButton to hide the 'Back' text present by
    // default in the back button.
    UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:NULL];
    
    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]}forState:UIControlStateNormal];//将title 文字的颜色改为透明
    
    
    return backBarButton;
}

// configure it before set left/right item
- (void)configureTitle
{
    // item color and font
    UIColor *itemTintColor = [UIColor colorWithRed:110/255.0 green:123/255.0 blue:139/255.0 alpha:1.0];
    UIFont *itemTextFont = [UIFont systemFontOfSize:15];
    self.tintColor = itemTintColor;
    NSDictionary *attributes = @{NSFontAttributeName:itemTextFont};
    [self setTitleTextAttributes:attributes forState:UIControlStateNormal];
}

- (void)configureTitleWithTintColor:(nonnull UIColor*)tintColor
{
    // item color and font
    UIFont *itemTextFont = [UIFont systemFontOfSize:15];
    self.tintColor = tintColor;
    NSDictionary *attributes = @{NSFontAttributeName:itemTextFont};
    [self setTitleTextAttributes:attributes forState:UIControlStateNormal];
}

// for ask chat page
- (void)configureTitleForChatAskPage
{
    // item color and font
    UIColor *itemTintColor = [UIColor colorWithRed:53.0/255.0 green:159.0/255.0 blue:220.0/255.0 alpha:1.0];
    UIFont *itemTextFont = [UIFont systemFontOfSize:15];
    self.tintColor = itemTintColor;
    NSDictionary *attributes = @{NSFontAttributeName:itemTextFont};
    [self setTitleTextAttributes:attributes forState:UIControlStateNormal];
}

@end
